/**
 * Copyright (c) CSIRO Australia, 2009
 *
 * @author $Author: jia020 $
 * @version $Id: Config.java 643 2009-05-20 00:20:55Z jia020 $
 */
package au.csiro.nt.pdsp.util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * Singleton Config class to load the bootstrap parameters from external(e.g.
 * database or pdsp-config.xml
 * 
 * @author jia020
 */
public class Config {
	public final String DB_JDBC = "jdbc:mysql://127.0.0.1:3306/pdsp";
	public final String DB_USER = "pdsp";
	public final String DB_PIN = "Centie2nat";
	public Map<String, String> columnsMap = null;
	public MySQL mysql = null;
	public MySQL mysql2 = null;
	public PdspLogger pdspLogger = null;
	public String URL_MESSAGE_LINK = "http://localhost:8080/Pdsp.html";
	private static Config myconf = null;

	private Config() {
		columnsMap = new HashMap<String,String>();		
		columnsMap.put("workflowid","integer");
		columnsMap.put("centrelinkid","string");
		columnsMap.put("driverid","string");
		columnsMap.put("firstname","string");
		columnsMap.put("lastname","string");
		columnsMap.put("birthday","date");
		columnsMap.put("martial","string");
		columnsMap.put("residentialaddress","string");
		columnsMap.put("suburb","string");
		columnsMap.put("postcode","string");
		columnsMap.put("phone","string");
		columnsMap.put("mobile","date");
		columnsMap.put("email","string");	
		columnsMap.put("income","float");
		columnsMap.put("assetvalue","float");	
		columnsMap.put("healthy","string");		
		columnsMap.put("helplog","string");		
		columnsMap.put("logs","string");
		mysql = new MySQL(DB_USER, DB_PIN, DB_JDBC);
		mysql2 = new MySQL(DB_USER, DB_PIN, DB_JDBC);
		
		String sSql = "select name ,value from config";
		String name,value;
		ResultSet rsSearch = mysql.execSelect(sSql);
		try {	
			if (rsSearch != null) {
				while (rsSearch.next()) {
					name = rsSearch.getString("name");		
					value = rsSearch.getString("value");
					if (name.equalsIgnoreCase("url_message_link"))
						URL_MESSAGE_LINK = value;
				}
			} 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		pdspLogger = new PdspLogger();
	}

	static {
		myconf = new Config();
	}

	public static Config getInstance() {
		return myconf;
	}
}
